package com.jingxing.controller;


import com.jingxing.config.ApiResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * 登录相关
 */
@Slf4j
@RestController
@Api(value = "API", tags = {"登录相关"})
public class LoginController {
    @Autowired
    private RestTemplate restTemplate;

    private static final String URL_20001="http://JINGXINGPROJECT-SERVER";
    /**
     * 登录
     * @param phone
     * @param code
     * @return
     */
    @PostMapping("/login")
    @ApiOperation(value = "登录", notes = "登录", response = String.class)
    public ApiResult login(String phone, String code){
        MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<>();
        requestEntity.add("phone",phone);
        requestEntity.add("code",code);
        return restTemplate.postForObject(URL_20001 + "/login",requestEntity,ApiResult.class);
    }

//    /**
//     * 根据token获取登录用户信息
//     *
//     * @return
//     */
//    @PostMapping("/getLoginInfo")
//    @ApiOperation(value = "根据token获取登录用户信息", response = PlayerInfo.class)
//    public ApiResult getLoginInfo(String token){
//        if(token==null){
//            return ApiResult.parameterError("token不能为空");
//        }
//        PlayerInfo playerInfo = loginService.getLoginInfo(token);
//        if(playerInfo==null){
//            return ApiResult.parameterError("token获取失败");
//        }
//        return ApiResult.result(ApiCode.SUCCESS,playerInfo);
//
//    }
//
//    /**
//     * 退出登录
//     * @param request
//     * @return String
//     */
//    @PostMapping("/logout")
//    @ApiOperation(value = "退出登录", notes = "退出登录", response = String.class)
//    public ApiResult<String> logout(HttpServletRequest request) {
//        loginService.logout(request);
//        return ApiResult.ok("退出成功");
//    }

}
